<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>注册</title>
		<style type="text/css">
			.sign{
				color: red;
			}
		</style>
		<script>
			function createXmlHttpRequest(){			
				if(window.XMLHttpRequest){
					// 高版本浏览器
					return new XMLHttpRequest() ;
				}else{
					// 兼容低版本浏览器(IE5、IE6以及更低版本的浏览器)
					return new ActiveXObject("Microsoft.XMLHTTP") ;
				}
			}
			
			function check(){
				var xmlHttpRequest = createXmlHttpRequest() ;
				// 获取用户输入的值
				var email = document.getElementById("userEmail").value ;
				xmlHttpRequest.open("GET","checkemail?useremail="+email,true) ;
				/* xmlHttpRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded") ;
				xmlHttpRequest.send("userEmail="+userEmail) ; */
				xmlHttpRequest.send(null) ;			
				xmlHttpRequest.onreadystatechange = callback ;
				console.log(xmlHttpRequest);
				
				function callback(){
				console.log(xmlHttpRequest.readyState);
				console.log(xmlHttpRequest.status == 200);
					// 判断客户端状态和服务器的状态
					if(xmlHttpRequest.readyState == 4 && xmlHttpRequest.status == 200 ){
						var msg = document.getElementById("verify") ;
						msg.innerHTML = "" ;
						if(xmlHttpRequest.responseText == 0){
							msg.style.display = "block" ;
							msg.style.color = "red" ;
							msg.innerHTML = "该邮箱已被使用" ;
						}else if(xmlHttpRequest.responseText == 1){
							msg.style.display = "block" ;
							msg.style.color = "green" ;
							msg.innerHTML = "该邮箱可以使用" ;
						}else{
							msg.innerHTML = "" ;
							msg.style.display = "block" ;
						}
					}
				}
			}
		</script>
	</head>
	<body>
		<div>
			<form action="" method="post">
				<p>注册邮箱：
					<input type="text" id="userEmail" onblur="check()"/>
					<span class="sign">*<span>
				</p>
				<p id="verify" display="none"></p>
				<p>用户名：&nbsp;
					<input type="text"  />
					<span class="sign">*</span>
				</p>
				<p>密&nbsp;&nbsp;&nbsp;码：
					<input type="password" />
					<span class="sign">*</span>
				</p>
			</form>
		</div>
	</body>
</html>

